package handler

import (
	"context"
	"fmt"
	"math/rand"
	"time"

	commonSdk "github.com/wangzhe1991/grpc-sdk/pb/common"
	userSdk "github.com/wangzhe1991/grpc-sdk/pb/user"

	"gitee.com/krio/grpc-go-server/internal/service/user"
	"gitee.com/krio/helper/logger"
)

type UserCmdHandler struct {
	user *user.UserService
}

func NewUserCmdHandler(
	userSvc *user.UserService,
) *UserCmdHandler {
	return &UserCmdHandler{
		user: userSvc,
	}
}

func (cu *UserCmdHandler) AddFillUser(num int) error {
	rand.Seed(time.Now().UnixNano())
	for i := 0; i < num; i++ {
		randNum := rand.Intn(100000000)
		res, err := cu.user.UserAdd(context.Background(), &userSdk.UserCreateReq{
			PhoneNumber:   fmt.Sprintf("153%d", randNum),
			Email:         fmt.Sprintf("test%d@163.com", randNum),
			PhoneAreaCode: "+86",
			Password:      "25d55ad283aa400af464c76d713c07ad", // 12345678
			FirstName:     "张",
			LastName:      fmt.Sprintf("三%d", randNum),
			Gender:        commonSdk.Gender_GENDER_MALE,
			Birthday:      "2021-01-01",
		})
		if err != nil {
			return err
		}
		logger.Info("新增用户成功！", res)
	}

	return nil
}
